package com.springboot.seckill.service;

import com.springboot.seckill.error.BusinessException;
import com.springboot.seckill.service.model.ItemModel;

import java.util.List;

/**
 * @Author: HuangDekai
 * @Date: 2022/3/18 8:50
 * @Version: 1.0
 * @since: jdk11
 */
public interface ItemService {
    /**
     * 创建商品
     * @param itemModel itemModel
     * @return itemModel
     */
    ItemModel createItem(ItemModel itemModel) throws BusinessException;

    /**
     * 商品浏览列表
     * @return 商品浏览列表
     */
    List<ItemModel> listItems();

    /**
     * 通过Id查询商品详情
     * @param id id
     * @return ItemModel
     */
    ItemModel getItemById(Integer id);

    /**
     * 库存扣减
     * @param itemId 商品id
     * @param amount 商品数量
     * @return 是否扣减成功
     * @throws BusinessException 商品id不存在/数量不正确
     */
    boolean decreaseStock(Integer itemId, Integer amount) throws BusinessException;

    /**
     * 增加商品销量
     * @param itemId 商品id
     * @param amount 增加的销量的数量
     * @throws BusinessException 商品id不存在/数量不正确
     */
    void increaseSales(Integer itemId, Integer amount) throws BusinessException;
}
